<?php



  $text = '';

  preg_match('/(<a\s+name="civilnews"\s+class="focustop-anchor"><\/a>.+)<a\s+name="imagenews"/is', $news_txt, $m);

  if ($m[1]) {
    $text .= preg_replace_callback('/(<img [^>]*)r\_src="([^\"]+)/i', 'copy_pic', $m[1]);

  }

  //echo $text;















function copy_pic($matches) {

  global $extra;

  static $step = 1;



  $url = $matches[2];

  $pic_dir = $extra['img_d'];

  $pic_name = basename($url);

  $save_name = $step.'_'.base64_encode($pic_name);

  if (preg_match('/\.(jpe?g|gif|png)/i', $url, $m_pic)) {

    $im_type = preg_replace('/jpeg/i', 'jpg', $m_pic[1]);

  } else {

    if ($hds = get_headers($url,1) && isset($hds['Content-Type'])) {

      $im_type = preg_replace('/image\//i', '', $hds['Content-Type']);

    } else {

      $im_type = 'jpg';

    }

  }

  if (file_exists($pic_dir.'/'.$save_name.'.'.$im_type)) {

    $url = 'inc/'.$pic_dir.'/'.$save_name.'.'.$im_type;

    $step++;

  } else {

    if ($im = read_file($url)) {

      foreach (@glob($pic_dir.'/'.$step.'_*') as $v) {

        @unlink($v);

      }

      write_file($pic_dir.'/'.$save_name.'.'.$im_type, $im);

      $url = 'inc/'.$pic_dir.'/'.$save_name.'.'.$im_type;

      $step++;

    }

  }

  return $matches[1].'src="'.$url;

}



?>